﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using Dataglot.Utils;

namespace Dataglot.CrossDb
{
    /// <summary>
    /// Executes ;+newline and GO+newline delimited strings in a cross db friendly fashion.
    /// </summary>
    public class GenericBatch
    {
        private readonly TraceSql trace = new TraceSql();
        
        private DataFactory factory;
        public GenericBatch(DataFactory targetFactory)
        {
            factory = targetFactory;
        }

        public void ExecuteBatch(string batch)
        {
            string[] sql = batch.Split(new string[]{@";
"}, StringSplitOptions.RemoveEmptyEntries);

            using (ParameterlessCommand com = new ParameterlessCommand(factory))
            {
                foreach (string s in sql)
                {
                    trace.Source.TraceInformation("Creating index with command : " + s);
                    com.Execute(s);
                }
            }
        }
    }
}
